<template>
	<view>
		<view class="goods-item">
			<view class="goods-item-left">
				<radio :checked='goods.goods_state' v-if="showRadio" color="#c00000" @click="changeRadio"></radio>
				<image class="goods-img" :src="goods.goods_small_logo|| defaultImg"></image>
			</view>
			<view class="goods-item-right">
				<view class="goods-title">
					{{goods.goods_name}}
				</view>
				<view class="goods_info_box">
					<view class="goods-price">
						￥{{goods.goods_price|toFixed}}
					</view>
					<uni-number-box min="1" :value="goods.goods_count" @change="changeNum" v-if="showNum"></uni-number-box>
				</view>

			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "my-goods",
		props: {
			goods: {
				type: Object,
				default: () => {}
			},
			showRadio: {
				type: Boolean,
				default: false
			},
			showNum:{
				type:Boolean,
				default:false
			}
		},
		data() {
			return {
				defaultImg: 'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png'
			};
		},
		filters: {
			// 把数字处理为带两位小数点的数字
			toFixed(num) {
				return Number(num).toFixed(2)
			}
		},
		methods: {
			changeRadio() {
				this.$emit('changeRadio', {
					goods_id: this.goods.goods_id,
					goods_state: !this.goods.goods_state
				})
			},
			changeNum(count){
				this.$emit('changeNum',{
					goods_id:this.goods.goods_id,
					goods_count:Number(count)
				})
			}
		}
	}
</script>

<style lang="scss">
	.goods-item {
		padding: 10px 5px;
		display: flex;
		border-bottom: 1px solid #efefef;

		.goods-item-left {
			margin-right: 5px;
			display: flex;
			justify-content: space-between;
			align-items: center;

			.goods-img {
				width: 100px;
				height: 100px;
			}
		}

		.goods-item-right {
			display: flex;
			flex-direction: column;
			font-size: 14px;
			justify-content: space-between;

			.goods_info_box {
				display: flex;
				justify-content: space-between;
				align-items: center;

				.goods-price {
					font-size: 16px;
					color: #c00000;
				}
			}

		}
	}
</style>
